package com.luo.stock.controller;

import com.luo.stock.service.UserService;
import com.luo.stock.vo.resp.PageResult;
import com.luohai.stock.pojo.entity.SysRole;
import com.luohai.stock.pojo.entity.SysUser;
import com.luohai.stock.pojo.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author 奥观海
 * @Date 2024/9/15
 */
@RestController
@RequestMapping("/api")
@Api(value = "用户认证相关接口定义",tags = "用户功能-用户登录功能")
public class UserController {

    @Autowired
    private UserService userService;
    @PostMapping("/login")
    @ApiOperation(value = "用户登录功能",notes = "用户登录",response = R.class)
    public R<LoginRespVo> login(@RequestBody LoginReqVo vo){
        return userService.login(vo);
    }
    @GetMapping("/captcha")
    @ApiOperation(value = "验证码生成功能",response = R.class)
    public R<Map<String,String>> getCaptchaCode(){
        return userService.getCaptchaCode();
    }

    /**
     * 多条件综合查询用户分页信息
     * @return
     */
    @PostMapping("/users")
    @ApiOperation(value = "多条件综合查询用户分页信息")
    public R<PageResult<SysUserVo>> getUsersPageVo(@RequestBody UsersPageVo usersPageVo){
        return userService.getUsersPageVo(usersPageVo);
    }
    /**
     * 添加用户信息
     * @return
     */
    @PostMapping("/user")
    @ApiOperation(value = "添加用户信息")
    public R<String> addUser(@RequestBody SysUser sysUser){
        return userService.addUser(sysUser);
    }
    /**
     * 获取用户具有的角色信息，以及所有角色信息
     * @return
     */
    @GetMapping("/user/roles/{userId}")
    @ApiOperation(value = "获取用户具有的角色信息，以及所有角色信息")
    public R<RoleVo> getUserRole(@PathVariable(value = "userId") String userId){
        return userService.getUserRole(userId);
    }
    @PutMapping("/user/roles")
    @ApiOperation("更新用户角色信息")
    public R<String> setRoles(@RequestBody UserAndRolesVo userAndRolesVo){
        return userService.setRoles(userAndRolesVo.getUserId(),userAndRolesVo.getRoleIds());
    }
    @ApiOperation("批量删除用户信息")
    @DeleteMapping("/user")
      public R<String> deleteUser(@RequestBody List<Long> userIds){
        return userService.deleteUser(userIds);
    }
    @GetMapping("/user/info/{userId}")
    @ApiOperation("根据用户id查询用户信息")
    public R<SysUserVo> getOneUser(@PathVariable("userId") String userId){
 return userService.getOneUser(userId);
    }
    @PutMapping("/user")
    @ApiOperation("根据id更新用户基本信息")
    public R<SysUserVo> updateOneUser(@RequestBody SysUser user){
        return userService.updateOneUser(user);
    }
}